package com.cxy.ch1.threadlocal;

/**
 * @ClassName: NoThreadLocal
 * @Description: TODO(无ThreadLocal类的线程)
 * @author 菜徐鸭
 * @date 2020年4月13日
 *
 */
public class NoThreadLocal {
	static Integer count = new Integer(1);

	/**
	 * 运行3个线程
	 */
	public void StartThreadArray() {
		Thread[] runs = new Thread[3];
		for (int i = 0; i < runs.length; i++) {
			runs[i] = new Thread(new TestTask(i));
		}

		for (int i = 0; i < runs.length; i++) {
			runs[i].start();
		}

	}

	public static class TestTask implements Runnable {
		int id;

		public TestTask(int id) {
			this.id = id;
		}

		@Override
		public void run() {
			// TODO Auto-generated method stub
			System.out.println(Thread.currentThread().getName() + ":线程开始start");
			count = count + id;
			System.out.println(Thread.currentThread().getName() + ": 变量count=" + count);
		}

	}
	
	public static void main(String[] args) {
		NoThreadLocal test=new NoThreadLocal();
		test.StartThreadArray();
	}
}
